From: Brion Vibber Date: Mon, 7 Feb 2005 03:03:26 +0000 (+0000) Subject: * (bug 1431) Avoid redundant objectcache garbage collection X-Git-Tag: 1.5.0alpha1~763 X-Git-Url: http://git.cyclocoop.org/%22.%24info%5B?a=commitdiff_plain;h=90d50200e85b18804261d31dee4ee32019863f9c;p=lhc%2Fweb%2Fwiklou.git * (bug 1431) Avoid redundant objectcache garbage collection Based on zigger's patch: http://bugzilla.wikimedia.org/attachment.cgi?id=238&action=view --- diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php index b476447adf..e1d13f89c2 100644 --- a/includes/ObjectCache.php +++ b/includes/ObjectCache.php @@ -214,6 +214,7 @@ CREATE TABLE objectcache ( */ class SqlBagOStuff extends BagOStuff { var $table; + var $lastexpireall = 0; function SqlBagOStuff($tablename = 'objectcache') { $this->table = $tablename; @@ -221,7 +222,7 @@ class SqlBagOStuff extends BagOStuff { function get($key) { /* expire old entries if any */ - $this->expireall(); + $this->garbageCollect(); $res = $this->_query( "SELECT value,exptime FROM $0 WHERE keyname='$1'", $key); @@ -313,9 +314,18 @@ class SqlBagOStuff extends BagOStuff { die( 'abstract function SqlBagOStuff::_fromunixtime() must be defined' ); } + function garbageCollect() { + $nowtime = time(); + /* Avoid repeating the delete within a few seconds */ + if ( $nowtime > ($this->lastexpireall + 1) ) { + $this->lastexpireall = $nowtime; + $this->expireall(); + } + } + function expireall() { /* Remove any items that have expired */ - $now=$this->_fromunixtime(time()); + $now = $this->_fromunixtime( time() ); $this->_query( "DELETE FROM $0 WHERE exptime<'$now'" ); }